#ifndef DBRECORD_H
#define DBRECORD_H

#include <QObject>
#include <QDateTime>
#include <QString>
#include <QContact>
#include <QIcon>

#include "settings.h"

QTM_USE_NAMESPACE

class DBRecord: public QObject
{
	Q_OBJECT

	public:
		DBRecord( QObject * parent = 0 );
		~DBRecord();
		int id() const { return m_id; }
		QTime startTime() const { return m_startTime.time(); }
		QDate startDate() const { return m_startTime.date(); }
		QDateTime startDateTime() const { return m_startTime; }
		QTime endTime() const { return m_endTime.time(); }
		QDate endDate() const { return m_endTime.date(); }
		QDateTime endDateTime() const { return m_endTime; }
		QString callDuration() const;
		EVENT_TYPE recordType() const { return m_recordType; }
		EVENT_DIRECTION direction() const { return m_direction; }
		QString name() const { return m_name; }
		QString phoneNumber() const { return m_phoneNumber; }

		const QContact * contact() const;
		QIcon avatar() const;

		void setId( int id ) { m_id = id; }
		void setStartTime( uint t ) { m_startTime.setTime_t( t ); }
		void setAvatar( QIcon av ) { m_avatar = av; }
		void setContact( QContact const & c );
		void setEndTime( uint t ) { m_endTime.setTime_t( t ); }
		void setRecordType( EVENT_TYPE type ) { m_recordType = type; }
		void setDirection( EVENT_DIRECTION s ) { m_direction = s; }
		void setName( QString & n ) { m_name = n; }
		void setPhoneNumber( QString & p ) { m_phoneNumber = p; }

		virtual CALL_TYPE callType() const { return CT_NONE; }
		virtual void setCallType( CALL_TYPE c ) { Q_UNUSED( c ); }
		virtual bool isRead() const { return false; }
		virtual QString text() const { return QString( "" ); }
		virtual void setRead( bool r ) { Q_UNUSED( r ); }
		virtual void setText( QString & t ) { Q_UNUSED( t ); }

	protected:
		EVENT_TYPE m_recordType;
		EVENT_DIRECTION m_direction;
		QString m_name;
		QString m_phoneNumber;
		QDateTime m_startTime;
		QDateTime m_endTime;
		QIcon m_avatar;
		QContact * m_contact;
		int m_id;


	signals:
		void contactRequested( int id ) const;
};

class CallRecord : public DBRecord
{
	Q_OBJECT

	public:
		CallRecord( QObject * parent = 0 ): DBRecord( parent ) {;}
		CALL_TYPE callType() const { return m_callType; }
		void setCallType( CALL_TYPE c ) { m_callType = c; }

	private:
		CALL_TYPE m_callType;
};

class SMSRecord: public DBRecord
{
	Q_OBJECT

	public:
		SMSRecord( QObject * parent = 0 ): DBRecord( parent ) {;}
		bool isRead() const { return m_isRead; }
		QString text() const { return m_text; }
		void setRead( bool r ) { m_isRead = r; }
		void setText( QString & t ) { m_text = t; }

	private:
		bool m_isRead;
		QString m_text;
};

#endif // DBRECORD_H
